using System;
using Castle.MonoRail.ActiveRecordSupport;
using Castle.MonoRail.Framework;
using IronMis2.Models;

namespace IronMis2.Controllers
{
    public class BankBussController:BaseController
    {
        public void Bank_bus()
        {
            PropertyBag["bankBuss"] = BankBussess.FindAll();
        }

        public void BankBussEdit(Guid id)
        {
            PropertyBag["bankBuss"] = BankBussess.Find(id);
            PropertyBag["employees"] = Employee.FindAll();
            RenderView("BankBussDetail");
        }

        public void BankBussUpdate([ARDataBind("bankBuss", AutoLoad = AutoLoadBehavior.Always)] BankBussess bankbuss)
        {
            bankbuss.UpdateAndFlush();
            RedirectToAction("Bank_bus");
        }

        public void BankBussDelete(Guid id)
        {
            BankBussess.Find(id).DeleteAndFlush();
            RedirectToAction("Bank_bus");
        }

        public void BankBussAdd()
        {
            PropertyBag["employees"] = Employee.FindAll();
        }

        public void BankBussNew(
            [ARDataBind("bankBuss", AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey, Exclude = "Date")] BankBussess
                bankbuss)
        {
            string date = Request.Params["bankBuss.Date"];
            if (string.Empty != date)
            {
                DateTime result;
                if (DateTime.TryParse(date, out result))
                    bankbuss.Date = result;
            }
            bankbuss.CreateAndFlush();

            RedirectToAction("Bank_bus");
        }

        /*public void BankBussNew([DataBind("bankBuss")] BankBussess bankbuss)
        {
            bankbuss.CreateAndFlush();
            RedirectToAction("Bank_bus");
        }*/
    }
}